<template>
  <div class="header">
    <div class="userName" v-show="userName">
      你好，{{userName}}
    </div>
    <div class="userName" v-show="!userName">
      请先登录
    </div>
    <div class="login-out" @click="loginout()">
      <img src="../assets/icons/loginout.png" alt="">
    </div>
  </div>
</template>
<script>
export default {
  props: {
    userName: {
      type: String,
      required: true
    }
  },
  data() {
    return {};
  },
  methods: {
    //退出登录反回登录页面
    loginout() {
      //点击提示是否确定退出登录
      this.$confirm("是否确定退出登录", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$http(
            "/wgl_admin/index.php?app=admin&act=logout",
            "get",
            {},
            {},
            {},
            success => {
              this.$message.success("退出登录成功");
              sessionStorage.removeItem("loginMsg");
              let self = this;
              setTimeout(() => {
                self.$router.push({ name: "login" });
              }, 1000);
            },
            error => {
              console.log(error);
            }
          );
        })
        .catch(() => {});
    }
  }
};
</script>
<style lang="scss" scoped>
.header {
  width: 100%;
  height: 70px;
  line-height: 70px;
  border-bottom: 1px solid #e6e8f4;
  position: relative;
  .userName {
    width: 100%;
    text-align: center;
    font-size: 14px;
    color: #999;
  }
  .login-out {
    width: 70px;
    height: 70px;
    background: #e6e8f4;
    border-left: 1px solid #e6e8f4;
    cursor: pointer;
    position: absolute;
    top: 0;
    right: 0;
    > img {
      position: absolute;
      display: block;
      margin: auto;
      top: 0;
      bottom: 0;
      right: 0;
      left: 0;
    }
  }
}
</style>
